/**
 * 消灭星星小游戏
 * @author cx330
 * @returns undefined
 */
function random(min,max){
    return Math.floor(Math.random()*(max-min+1)+min)
}
t1 = setInterval(function () {
var bloodObj = document.querySelector('.blood')
var bloodWidth = parseInt(bloodObj.style.width)
bloodWidth -= 15
bloodObj.style.width = bloodWidth + 'px'
if (bloodWidth == -10) {
    clearInterval(t1)
    clearInterval(t2)
    alert('GAME OVER')
}
}, 500)

var btnObj = document.querySelector('button')
btnObj.onclick = function () {
var bloodObj = document.querySelector('.blood')
bloodObj.style.width = '200px'
var bloodWidth = parseInt(bloodObj.style.width)
}


t2  =  setInterval(function(evt) {
var bodyObj = document.body
bodyObj.onclick = function(evt) {
var e = evt || window.event
var target = e.target || e.srcElement
if (target.nodeName === 'IMG')
{
    bodyObj.removeChild(target)
    var bloodObj = document.querySelector('.blood')
        var bloodWidth = parseInt(bloodObj.style.width)
        bloodWidth += 10
        bloodObj.style.width = bloodWidth + 'px'


        if (bloodWidth > 200) {
            bloodWidth = 200
            bloodObj.style.width = bloodWidth + 'px'
            console.log(bloodWidth);
        }
}
}
var imgObj = document.createElement('img')
imgObj.src = './5.jpg'
var min = 50
var max = 150
imgObj.width = random(min,max)
imgObj.style.position = 'absolute'
var min = 0
var max = (window.innserWidth || document.documentElement.clientWidth) - imgObj.width
imgObj.style.left = random(min,max) + 'px'
var max = (window.innerHeight || document.documentElement.clientHeight) - imgObj.width
imgObj.style.top = random(min,max) + 'px'
document.body.appendChild(imgObj)
}, 300)